//
//  ZBookShelfCollectionCell.m
//  ZQLearn
//
//  Created by lipei on 2019/6/10.
//  Copyright © 2019 macfeel. All rights reserved.
//

#import "ZBookShelfCollectionCell.h"

@interface ZBookShelfCollectionCell ()

@end
@implementation ZBookShelfCollectionCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = kWhiteColor;
        
        [self.headImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(self.contentView.width-10);
            make.height.mas_equalTo(ScreenWidth>375?170.f:155.f);
            make.top.mas_equalTo(10);
            make.centerX.equalTo(self.contentView);
        }];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headImg.mas_bottom).offset(5);
            make.centerX.equalTo(self.contentView);
        }];
        [self.chooseImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headImg.mas_top).offset(10);
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.size.mas_equalTo(CGSizeMake(20,20));
        }];
        [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.headImg.mas_top);
            make.bottom.equalTo(self.headImg.mas_bottom);
            make.left.equalTo(self.headImg.mas_left);
            make.right.equalTo(self.headImg.mas_right);
        }];
        self.chooseImg.hidden = YES;
        self.button.hidden = YES;
    }
    return self;
}

#pragma mark - 是否处于编辑状态

- (void)setInEditState:(BOOL)inEditState
{
    if (inEditState && _inEditState != inEditState) {
        
        self.chooseImg.hidden = NO;
        self.button.hidden = NO;
    } else {
        
        self.chooseImg.hidden = YES;
        self.button.hidden = YES;
    }
}

#pragma mark - init

- (UIImageView *)headImg{
    if (!_headImg) {
        _headImg = [[UIImageView alloc] init];
        _headImg.image = [UIImage imageNamed:@"touxiang"];
        [self addSubview:_headImg];
    }
    return _headImg;
}

- (UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = [UIFont systemFontOfSize:12];
        _titleLab.textColor = kDarkGrayColor;
        _titleLab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_titleLab];
    }
    return _titleLab;
}

- (UIImageView *)chooseImg{
    if (!_chooseImg) {
        _chooseImg = [[UIImageView alloc] init];
        [self addSubview:_chooseImg];
    }
    return _chooseImg;
}
- (void)setChecked:(BOOL)checked
{
    if (checked) {
        _chooseImg.image = [UIImage imageNamed:@"选中"];
    }
    
    else
    {
        _chooseImg.image = [UIImage imageNamed:@"选中拷贝2"];
    }
}

- (UIButton *)button
{
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeSystem];
        [_button setBackgroundColor:[UIColor clearColor]];
        [self addSubview:_button];
    }
    return _button;
}

@end
